package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachPlanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachPlanDto;
import com.xuecheng.content.model.dto.TeachPlanDto;
import com.xuecheng.content.service.TeachPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2024-06-11
 * Time: 22:51
 */
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
@RestController
public class TeachPlanController {

    @Resource
    private TeachPlanService teachPlanService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId", name = "课程Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachPlanDto> getTreeNodes(@PathVariable Long courseId) {
        List<TeachPlanDto> teachPlanTree = teachPlanService.findTeachPlanTree(courseId);
        return teachPlanTree;
    }


    @ApiOperation("课程计划的创建和修改")
    @PostMapping("/teachplan")
    public void saveTeachPlan(@RequestBody @Validated SaveTeachPlanDto saveTeachPlanDto) {
        teachPlanService.saveTeachPlan(saveTeachPlanDto);
    }

    @ApiOperation("课程计划的删除")
    @DeleteMapping("/teachplan/{teachPlanId}")
    public void deleteTeachPlan(@PathVariable Long teachPlanId) {
        teachPlanService.removeTeachPlan(teachPlanId);
    }


    @ApiOperation(value = "移动课程计划")
    @PostMapping("teachplan/{moveType}/{teachPlanId}")
    public void moveTeachPlan(@PathVariable String moveType, @PathVariable Long teachPlanId) {
        teachPlanService.moveTeachPlan(teachPlanId, moveType);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachPlanMediaDto bindTeachPlanMediaDto) {
        teachPlanService.associationMedia(bindTeachPlanMediaDto);
    }


    @ApiOperation(value = "课程计划和媒资信息解绑")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void associationMedia(@PathVariable Long teachPlanId, @PathVariable String mediaId) {
        teachPlanService.unbindMedia(teachPlanId, mediaId);
    }


}
